package com.ruoyi.pcwl.map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pcwl.domain.*;
import com.ruoyi.pcwl.domain.enums.CarouselTypeEnum;
import com.ruoyi.pcwl.domain.vo.CarouselVo;
import com.ruoyi.pcwl.service.AppVedioService;
import com.ruoyi.pcwl.service.CarouselService;
import com.ruoyi.pcwl.service.IAppCarouselService;
import com.ruoyi.pcwl.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 文章信息，存储已发布的文章Controller
 *
 * @author ruoyi
 * @date 2024-01-11
 */
@Api(tags = "小程序端地图接口")
@RestController
@RequestMapping("/app/map")
public class MapAPIExample extends BaseController
{

//    /**
//     * 查询文章信息，存储已发布的文章列表
//     */
//    @ApiOperation("分页获取已发布到小程序的视频列表")
////    @PreAuthorize("@ss.hasPermi('system:article:list')")
//    @GetMapping("/listAppVedio")
//    public TableDataInfo listAppVedio(AppVedio appVedio)
//    {
//        Integer pageNum = Convert.toInt(ServletUtils.getParameter("pageNum")==null?1:ServletUtils.getParameter("pageNum"));
//        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize")==null?10:ServletUtils.getParameter("pageSize"));
//        Page<AppVedio> appVedioPage = new Page<>(pageNum, pageSize);
//        IPage<AppVedio> appVedioIPage = appVedioService.getPublishVedio(appVedioPage,appVedio);
//        return getDataTable(appVedioIPage);
//    }


//    /**
//     * 查询文章信息，存储已发布的文章列表
//     */
//    @ApiOperation("分页获取已发布到小程序的文章列表")
////    @PreAuthorize("@ss.hasPermi('system:article:list')")
//    @GetMapping("/listAppArticle")
//    public TableDataInfo listArticle(Article article)
//    {
//        Integer pageNum = Convert.toInt(ServletUtils.getParameter("pageNum")==null?1:ServletUtils.getParameter("pageNum"));
//        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize")==null?10:ServletUtils.getParameter("pageSize"));
//        Page<Article> articlePage = new Page<>(pageNum, pageSize);
//        IPage<Article> articleIPage = articleService.getPublishArticle(articlePage,article);
//        return getDataTable(articleIPage);
//    }

    /**
     * 根居ip获取用户位置
     */
    @ApiOperation("根据ip获取用户位置")
    @GetMapping("/getUserLocal")
    public AjaxResult getUserLocal() throws JsonProcessingException {

//        方式一
//        String s = HttpClientUtils.sendGet("https://apis.map.qq.com/ws/location/v1/ip?ip=111.206.145.41&key=SZUBZ-NKQ6N-2FHF3-SQOOE-NP2BV-2HF4U");

        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("ip","111.206.145.41");
        stringObjectHashMap.put("key","SZUBZ-NKQ6N-2FHF3-SQOOE-NP2BV-2HF4U");
        String s = HttpClientUtils.sendGet("https://apis.map.qq.com/ws/location/v1/ip", stringObjectHashMap);
        return AjaxResult.success(s);
    }

    /**
     * 根居ip获取用户位置
     */
    @ApiOperation("根据经纬度获取地址")
    @GetMapping("/getLocation")
    public AjaxResult getLocation(String lng,String lat) throws JsonProcessingException {

//        https://apis.map.qq.com/ws/geocoder/v1/?location=39.984154,116.307490&key=[你的key]&get_poi=1
//        方式一
//        String s = HttpClientUtils.sendGet("https://apis.map.qq.com/ws/location/v1/ip?ip=111.206.145.41&key=SZUBZ-NKQ6N-2FHF3-SQOOE-NP2BV-2HF4U");
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("location",lat+","+lng);
        stringObjectHashMap.put("key","SZUBZ-NKQ6N-2FHF3-SQOOE-NP2BV-2HF4U");
        stringObjectHashMap.put("get_poi","1");
        String s = HttpClientUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", stringObjectHashMap);
        return AjaxResult.success(s);
    }

}
